import os.path
import time
import unittest
from test_cases import test_demo1, test_demo2
import ddt
from HTMLTestRunner import HTMLTestRunner

'''
class Demo1TestCase(unittest.TestCase):
    def test1(self):
        print('test1')

    def test2(self):
        print('test2')


class Demo2TestCase(unittest.TestCase):
    def testa(self):
        print('testa')

    def testb(self):
        print('testb')


if __name__ == '__main__':
    # 创建suite对象 收集器
    suite = unittest.TestSuite()
    # suite.addTest(Demo1TestCase('test1'))
    # suite.addTest(Demo1TestCase('test2'))
    # suite.addTest(Demo2TestCase('testb'))
    data_list = [
        Demo1TestCase('test1'),
        Demo1TestCase('test2'),
        Demo2TestCase('testb')
                  ]
    # 调用addTests(list)
    suite.addTests(data_list)
    # 执行器
    # runner 
    # 创建执行器对象
    runner = unittest.TextTestRunner(verbosity=2)
    runner.run(suite)
'''

'''
# 创建加载器对象, 加载测试类
loader = unittest.TestLoader()
# unittest.defaultTestLoader == unittest.TestLoader()
# 参数:测试类
loader1 = loader.loadTestsFromTestCase(test_demo1.Demo1TestCase)
loader2 = loader.loadTestsFromTestCase(test_demo2.Demo2TestCase)
# 创建suite对象,收集测试类
suite = unittest.TestSuite()
suite.addTests([loader1, loader2])
# 创建执行器,执行测试类
runner = unittest.TextTestRunner(verbosity=2)
runner.run(suite)
'''

'''
# loader
# 参数:模块名(字符串类型)
loader1 = unittest.defaultTestLoader.loadTestsFromName('test_cases.test_demo1')
# 类名
loader2 = unittest.defaultTestLoader.loadTestsFromName('test_cases.test_demo1.Demo1TestCase')
# 方法名
loader3 = unittest.defaultTestLoader.loadTestsFromName('test_cases.test_demo1.Demo1TestCase.test1')
# loadTestsFromNames与addTests类似
# suite
suite = unittest.TestSuite()
loader_list = [loader1, loader2, loader3]
suite.addTests(loader_list)
# runner
runner = unittest.TextTestRunner(verbosity=2)
runner.run(suite)
'''

'''
# loader
# 参数:模块名
loader1 = unittest.defaultTestLoader.loadTestsFromModule(test_demo1)
loader2 = unittest.defaultTestLoader.loadTestsFromModule(test_demo2)
# suite
suite = unittest.TestSuite()
suite.addTests([loader1, loader2])
# runner
runner = unittest.TextTestRunner(verbosity=2)
runner.run(suite)
'''

'''
# loader
# 加载模块的路径, 加载模块名的规则
# 返回的是suite
discover = unittest.defaultTestLoader.discover('./test_cases', 'test*')
# runner
runner = unittest.TextTestRunner(verbosity=2)
runner.run(discover)
'''

'''
@ddt.ddt
class Demo1TestCase(unittest.TestCase):
    # 测试数据
    data_list = [
        {'username': 'file1', 'password': '123456'},
        {'username': 'file2', 'password': '123456'}
    ]

    @ddt.data(*data_list)
    def test_login(self, data):
        print(data)


if __name__ == '__main__':
    unittest.main(verbosity=2)
'''

'''
#loader
loader = unittest.defaultTestLoader.discover('test_cases', 'test*')

# runner
# 准备写入的文件名和路径
file_dict = os.path.abspath('report')
file_name = time.strftime("%Y%m%d%H%M%S") + '-demo.html'
file_path = os.path.join(file_dict, file_name)
# 写入文件,执行用例,生成测试报告
with open(file_path, 'wb') as f:
    runner = HTMLTestRunner(
        title='测试报告标题',
        description='测试报告描述',
        tester='hess',
        stream=f,
        verbosity=2    
    )
    runner.run(loader)
'''